---
title: Delete (complete) a task
summary: Mark a task as completed/deleted via the pk82036_task.task_delete stored procedure.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-08-21
library: SAIF.Business.Tasks
reference_type: embedded
operation_id: OP-4
trigger: Application calls delete on a task
---

# Delete (complete) a task

This operation logically completes/deletes a task by calling `pk82036_task.task_delete`, again protected by the `UPDATE_SEQ_NUM` optimistic-concurrency token.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-4 |
| **Trigger** | Application calls delete on a task |
| **Inputs** | Existing `clsTask` instance |
| **Outputs** | Updated `TASK` row (soft-delete)* |
| **Primary components** | `clsTask.BeforeDelete`, `clsTask.AfterDelete` |
| **Entry point** | `SAIF.Business.Tasks/clsTask.vb` |

## Steps

1. Build a `NonQuery` `StoredProcedure` request on `pk82036_task.task_delete` (`DataRequest.ID = "DELETE"`) ([SQL-014](../sql/SQL-014-delete-task.md), [TASK](../database-tables.md#task)).
2. Set `UpdateUser` from `DPI.UserID`.
3. Pass parameters `TaskSeqNum`, `UpdateSeqNum` (optimistic concurrency, [BR-013](../business-rules.md#br-013-optimistic-concurrency-via-update-sequence-number)), `UpdateUser`, and `RowsAffected` (`ReturnValue`).
   > **Origin**: The `task_delete` procedure body resides in the Oracle database and was not retrieved in this analysis pass; its soft-delete semantics are inferred, not confirmed.**
4. Framework executes the request against the DPI.
5. After execution:
   - `RowsAffected <> 1` → `AddErrorMessage("DeleteError", clsConstants.Messages.DBContentionError)` ([BR-012](../business-rules.md#br-012-task-delete-must-affect-exactly-one-row)).
   - Otherwise: remove the message.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([Delete called on task]) --> S1["BeforeDelete builds<br>task_delete request"]
	S1 --> S2[Framework executes request]
	S2 --> D{RowsAffected = 1?}
	D -->|No| ErrEnd(["DeleteError:<br>DBContentionError"])
	D -->|Yes| EndOk(["Message cleared — task<br>completed"])
```

## Failure and edge-case behavior

- A stale `UpdateSeqNum` yields `RowsAffected = 0`, surfaced as `DBContentionError` ([BR-012](../business-rules.md#br-012-task-delete-must-affect-exactly-one-row), [BR-013](../business-rules.md#br-013-optimistic-concurrency-via-update-sequence-number)).
- The `DELETE_FLAG` column and the `ShowCompleted` search filter indicate this is logically a "completed" soft-delete handled inside the stored procedure, not a physical row delete*.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- SAIF.Business.Tasks/clsTask.vb
